package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.validator.constraints.Range;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "withdraw")
@org.hibernate.annotations.Table(appliesTo = "withdraw", comment = "提现记录表")
public class Withdraw {

    @Id
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @ApiModelProperty(value = "用户ID", example = "1")
    @Column(columnDefinition = "bigint comment '用户ID'")
    private Long userId;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "真实姓名", example = "真名")
    @Column(columnDefinition = "varchar(128) comment '真实姓名'")
    private String name;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "银行卡号", example = "998...")
    @Column(columnDefinition = "varchar(128) comment '银行卡号'")
    private String bankCard;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "开户行地址", example = "开户行地址")
    @Column(columnDefinition = "varchar(256) comment '开户行地址'")
    private String bankName;

    @NotNull(groups = {ActionModel.Insert.class})
    @Min(value = 0,groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "提现金额", example = "9.9")
    @Column(columnDefinition = "decimal(12,2) comment '提现金额'")
    private BigDecimal money;

    @ApiModelProperty(value = "提现状态: AUDITING#审核中,AUDIT_FAIL#审核不通过,SUCCESS#成功,FAIL#失败", example = "AUDITING")
    @Column(columnDefinition = "varchar(64) comment '提现状态: AUDITING#审核中,AUDIT_FAIL#审核不通过,SUCCESS#成功,FAIL#失败'")
    private String status;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;

    /**
     * 扩展字段
     */
    @Transient
    @ApiModelProperty(value = "昵称", hidden = true)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String nickname;

    /**
     * 扩展查询字段
     */
    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始时间", hidden = true)
    private Timestamp startTime;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询结束时间", hidden = true)
    private Timestamp endTime;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询排序字段", hidden = true)
    private String orderField;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始索引", hidden = true)
    private Integer startIndex;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询返回数量", hidden = true)
    private Integer limit;
}
